#ifndef _DS1341_H_
#define _DS1341_H_

#include "stm32f10x.h"

#define HT1382_SCLK_PIN    	GPIO_Pin_1
#define HT1382_SCLK_PORT   	GPIOC
#define HT1382_SCLK_RCC    	RCC_APB2Periph_GPIOC
#define HT1382_SCLK_L  			GPIO_ResetBits(HT1382_SCLK_PORT,HT1382_SCLK_PIN)
#define HT1382_SCLK_H  			GPIO_SetBits(HT1382_SCLK_PORT,HT1382_SCLK_PIN)
 
#define HT1382_SDIN_PIN    GPIO_Pin_0
#define HT1382_SDIN_PORT   GPIOC
#define HT1382_SDIN_RCC    RCC_APB2Periph_GPIOC
#define HT1382_SDIN_L  		 GPIO_ResetBits(HT1382_SDIN_PORT,HT1382_SDIN_PIN)
#define HT1382_SDIN_H      GPIO_SetBits(HT1382_SDIN_PORT,HT1382_SDIN_PIN)
#define HT1382_SDIN_READ   GPIO_ReadInputDataBit(HT1382_SDIN_PORT,HT1382_SDIN_PIN)

#define HT1382_INT_GPIO_PORT                GPIOC
#define HT1382_INT_GPIO_RCC                 RCC_APB2Periph_GPIOC
#define HT1382_INT_GPIO_PIN                 GPIO_Pin_2
#define HT1382_INT_EXTI_PORTSOURCE          GPIO_PortSourceGPIOC
#define HT1382_INT_EXTI_PINSOURCE           GPIO_PinSource2
#define HT1382_INT_EXTI_LINE                EXTI_Line2
#define HT1382_INT_EXTI_IRQ                 EXTI2_IRQn      

#define HT1382_W_ADDR      0xD0
#define HT1382_R_ADDR      0xD1

typedef struct 
{
	unsigned char year;
	unsigned char mon;
	unsigned char day;
	unsigned char hour;
	unsigned char min;
	unsigned char sec;
}datetime;

enum
{
	REG_SECOND     = 0x00,
	REG_MINUTE,
	REG_HOUR,
	REG_DATE,
	REG_MONTH,
	REG_DAY,
	REG_YEAR, 
	REG_ST1,
	REG_ST2,
	REG_INT,
	REG_ALARM_SEC,
	REG_ALARM_MIN,
	REG_ALARM_HOU,
	REG_ALARM_DATE,
	REG_ALARM_MON,
	REG_ALARM_DAY,  
	REG_NUM
};

#define BIT0	0x01
#define BIT1	0x02
#define BIT2	0x04
#define BIT3	0x08
#define BIT4	0x10
#define BIT5	0x20
#define BIT6	0x40
#define BIT7	0x80

#define HT1382_ALARM_ONCE_SEC               0x0F
#define HT1382_ALARM_SEC_MATCH              0x0E
#define HT1382_ALARM_MINSEC_MATCH           0x0C
#define HT1382_ALARM_HOURMINSEC_MATCH       0x08
#define HT1382_ALARM_DATEHOURMINSEC_MATCH   0x00
#define HT1382_ALARM_DAYHOURMINSEC_MATCH    0x10

void ht1382_init(void);
datetime* RTCTime_get(void);
datetime* ht1382_get_time(void);
void ht1382_set_time(datetime *dt);
//void ht1382_set_alarm(datetime *dt, unsigned char mode);
void ht1382_set_alarm(void);
#endif

